<?php App::uses('CakeTime', 'Utility');?>
<?php     
	# faz o load de carregando na pagina, mas nao esta funcionando.
    echo $this->Paginator->options(array(
        'update' => '#content',
        'evalScripts' => true,
        'before' => $this->Js->get('#busy-indicator')->effect('fadeIn', array('buffer' => false)),
        'complete' => $this->Js->get('#busy-indicator')->effect('fadeOut', array('buffer' => false)),        
    ));
?>
<div class="pedidos index">

	<div class="row">
		<div class="col-md-12">
			<div class="page-header">
				<h1><?php echo __('Lista de Pedidos'); ?></h1>
			</div>
		</div><!-- end col md 12 -->
	</div><!-- end row -->
	<div class="row">
		<div class="col-md-3 col-xs-12">
			<div class="actions">
				<div class="panel panel-default">
					<div class="panel-heading"><h5>Ações</h5></div>
						<div class="panel-body">
							<ul class="nav nav-pills nav-stacked">
								<li><?php echo $this->Html->link(__('<span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;Novo Pedido'), array('action' => 'add'), array('escape' => false)); ?></li>
								<li><?php echo $this->Html->link(__('<span class="glyphicon glyphicon-list"></span>&nbsp;&nbsp;Listar Clientes'), array('controller' => 'clientes', 'action' => 'index'), array('escape' => false)); ?> </li>
								<li><?php echo $this->Html->link(__('<span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;Novo Cliente'), array('controller' => 'clientes', 'action' => 'add'), array('escape' => false)); ?> </li>
								<li><?php echo $this->Html->link(__('<span class="glyphicon glyphicon-list"></span>&nbsp;&nbsp;Listar Entradas'), array('controller' => 'entradas', 'action' => 'index'), array('escape' => false)); ?> </li>
								<li><?php echo $this->Html->link(__('<span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;Nova Entrada'), array('controller' => 'entradas', 'action' => 'add'), array('escape' => false)); ?> </li>
								<li><?php echo $this->Html->link(__('<span class="glyphicon glyphicon-list"></span>&nbsp;&nbsp;Listar Produtos'), array('controller' => 'produtos', 'action' => 'index'), array('escape' => false)); ?> </li>
								<li><?php echo $this->Html->link(__('<span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;Novo Produto'), array('controller' => 'produtos', 'action' => 'add'), array('escape' => false)); ?> </li>
							</ul>
						</div><!-- end body -->
				</div><!-- end panel -->
			</div><!-- end actions -->
		</div><!-- end col md 3 -->

		<div class="col-md-9">
			<div class="panel panel-default">
				<div class="panel-heading">
				
			
			<?php echo $this->Search->create('Filtro',array('class' => 'form-inline'));?>
					<div class="row">
						<div class="form-group col-md-4 col-sm-4 col-xs-8">
							<?php echo $this->Search->input('filter1', array('class' => 'form-control', 'between' => '<div class="input-group"><span class="input-group-addon">Cliente</span>', 'after' => '</div>'));?>
						</div>
						<div class="form-group col-md-3 col-sm-3 col-xs-4">
							<?php echo $this->Search->input('filter2', array('class' => 'form-control'));?>
						</div>
						<div class="form-group col-md-3 col-sm-3 col-xs-5">
							<?php echo $this->Search->input('filter3', array('class' => 'form-control'));?>
						</div>
						<div class="form-group col-md-2 col-sm-2 col-xs-3">
						
							<?php echo $this->Search->submit(__('Filtrar'),  array('class' => 'btn btn-default'));
							echo $this->Search->end();?>
						</div>
					</div>
				</div>
			<div class="table-responsive">
			<table cellpadding="0" cellspacing="0" class="table table-bordered">
				<thead>
					<tr>
						<!--<th><?php //echo $this->Paginator->sort('id'); ?></th>-->
						<th><?php echo $this->Paginator->sort('data_hora'); ?></th>
						<th><?php echo $this->Paginator->sort('mesa'); ?></th>
						<th><?php echo $this->Paginator->sort('status_entrega', 'Entregue'); ?></th>
						<th><?php echo $this->Paginator->sort('status_pagamento', 'Pagamento'); ?></th>
						<th><?php echo $this->Paginator->sort('valor_total', 'Total'); ?></th>
						<th><?php echo $this->Paginator->sort('status', 'Status'); ?></th>
						<th><?php echo $this->Paginator->sort('cliente_id'); ?></th>
						<th class="actions">Opções</th>
					</tr>
				</thead>
				<tbody>
				<?php foreach ($pedidos as $pedido): ?>
					<tr>
						<!--<td><?php //echo h($pedido['Pedido']['id']); ?>&nbsp;</td>-->
						<td><?php echo CakeTime::format($pedido['Pedido']['data_hora'], '%d/%m/%Y  às  %H:%M:%S'); ?>&nbsp;</td>
						<td><?php echo h($pedido['Pedido']['mesa']); ?>&nbsp;</td>
						<td><?php if($pedido['Pedido']['status_entrega'] == 0) echo h('Não'); else echo 'Sim'; ?>&nbsp;</td>
						<td><?php if($pedido['Pedido']['status_pagamento'] == 0) echo h('Não pagou'); else echo 'Pagou'; ?>&nbsp;</td>
						<td><?php echo h($pedido['Pedido']['valor_total']); ?>&nbsp;</td>
						<td><?php if($pedido['Pedido']['status'] == 0) echo h('Cancelado'); else echo 'Ativo'; ?>&nbsp;</td>
						<td><?php echo $this->Html->link($pedido['Cliente']['nome'], array('controller' => 'clientes', 'action' => 'view', $pedido['Cliente']['id'])); ?>
						</td>
						<td class="actions" width="161px">
							<?php //echo $this->Html->link('<span class="glyphicon glyphicon-search" title="Detalhes do Pedido"></span>', array('action' => 'view', $pedido['Pedido']['id']), array('escape' => false)); ?>
							<?php echo $this->Html->link('<span class="glyphicon glyphicon-ok-circle" title="Pedido Entregue?" style="margin-left:16px;padding-bottom:10px;"> Editar</span>', array('action' => 'edit', $pedido['Pedido']['id']), array('escape' => false)); ?>
							<?php echo $this->Form->postLink('<span class="glyphicon glyphicon-remove" title="Cancelar pedido?" style="margin-left:16px;"> Cancelar Pedido</span>', array('action' => 'cancelar', $pedido['Pedido']['id']), array('escape' => false), __('Tem certeza que deseja cancelar o pedido # %s?', $pedido['Pedido']['id'])); ?>
						</td>
					</tr>
				<?php endforeach; ?>
				</tbody>
			</table>
			</div>
			</div>

			<p>
				<small><?php echo $this->Paginator->counter(array('format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')));?></small>
			</p>

			<?php
			$params = $this->Paginator->params();
			if ($params['pageCount'] > 1) {
			?>
			<ul class="pagination pagination-sm">
				<?php
					echo $this->Paginator->prev('&larr; Previous', array('class' => 'prev','tag' => 'li','escape' => false), '<a onclick="return false;">&larr; Previous</a>', array('class' => 'prev disabled','tag' => 'li','escape' => false));
					echo $this->Paginator->numbers(array('separator' => '','tag' => 'li','currentClass' => 'active','currentTag' => 'a'));
					echo $this->Paginator->next('Next &rarr;', array('class' => 'next','tag' => 'li','escape' => false), '<a onclick="return false;">Next &rarr;</a>', array('class' => 'next disabled','tag' => 'li','escape' => false));
				?>
			</ul>
			<?php } ?>

		</div> <!-- end col md 9 -->
	</div><!-- end row -->
<?php
    //echo $this->Paginator->numbers();
    //echo $this->Js->writeBuffer();
?>

</div><!-- end containing of content -->